/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package luft27.comm.mavlink;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;

/**
 *
 * @author amalikov
 */
public class SysStatus implements MessagePayload {
	public int onboard_control_sensors_present;
	public int onboard_control_sensors_enabled;
	public int onboard_control_sensors_health;
	public short load;
	public short voltage_battery;
	public short current_battery;
	public short drop_rate_comm;
	public short errors_comm;
	public short errors_count1;
	public short errors_count2;
	public short errors_count3;
	public short errors_count4;
	public byte battery_remaining;

	@Override
	public byte[] get() {
		ByteBuffer bb = ByteBuffer.allocate(256).order(ByteOrder.LITTLE_ENDIAN);
		bb.putInt(onboard_control_sensors_present);
		bb.putInt(onboard_control_sensors_enabled);
		bb.putInt(onboard_control_sensors_health);
		bb.putShort(load);
		bb.putShort(voltage_battery);
		bb.putShort(current_battery);
		bb.putShort(drop_rate_comm);
		bb.putShort(errors_comm);
		bb.putShort(errors_count1);
		bb.putShort(errors_count2);
		bb.putShort(errors_count3);
		bb.putShort(errors_count4);
		bb.put(battery_remaining);
		return Arrays.copyOf(bb.array(), bb.position());
	}

	@Override
	public void set(byte[] data) {
		ByteBuffer bb = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);
		onboard_control_sensors_present = bb.getInt();
		onboard_control_sensors_enabled = bb.getInt();
		onboard_control_sensors_health = bb.getInt();
		load = bb.getShort();
		voltage_battery = bb.getShort();
		current_battery = bb.getShort();
		drop_rate_comm = bb.getShort();
		errors_comm = bb.getShort();
		errors_count1 = bb.getShort();
		errors_count2 = bb.getShort();
		errors_count3 = bb.getShort();
		errors_count4 = bb.getShort();
		battery_remaining = bb.get();
	}
}
